package cn.yunyichina.provider.clinic.thread;

import cn.yunyichina.provider.clinic.constant.CacheConstant;
import cn.yunyichina.provider.clinic.manager.ClinicBizManager;
import cn.yunyichina.provider.clinic.vo.ListMzfeeVoResponse;
import cn.yunyichina.provider.framework.common.PKGenerator;
import cn.yunyichina.provider.framework.data.SpringContextHandler;
import cn.yunyichina.provider.framework.dubbo.service.BaseService;
import cn.yunyichina.provider.framework.dubbo.service.CacheService;
import cn.yunyichina.provider.framework.dubbo.service.DrugService;
import cn.yunyichina.provider.framework.exception.CallException;
import cn.yunyichina.provider.iface.entity.base.OrderExtVo;
import cn.yunyichina.provider.iface.entity.base.OrderListVo;
import cn.yunyichina.provider.iface.entity.cache.SessionInfo;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.iface.entity.hisiface.clinic.FeeDetailVoResponse;
import cn.yunyichina.utils.commons.DateUtils;
import cn.yunyichina.utils.convert.JsonUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.*;

public class DrugMatchedRunnable implements Runnable {

    private Logger logger = LoggerFactory.getLogger(DrugMatchedRunnable.class);

    private String orderNo;

    private String sessionId;

    public DrugMatchedRunnable() {
        super();
    }

    public DrugMatchedRunnable(String sessionId, String orderNo) {
        this.sessionId = sessionId;
        this.orderNo = orderNo;
    }

    @Override
    public void run() {
        String userInfoJson = CacheService.getSessionKey(sessionId, CacheConstant.CACHE_SESSION_USER);
        SessionInfo userInfo = JsonUtils.parseObject(userInfoJson, SessionInfo.class);

        logger.info("【外购处方单-匹配药店药品信息-开始】, DrugMatchedRunnable,orderNo=" + orderNo);

        Map<String, String> orderDataMap = new HashMap<String, String>();
        orderDataMap.put("order_no", orderNo);
        logger.info("【外购处方单-根据条件查询药品匹配结果信息】, yyt.drug.matched.list request=" + JSON.toJSONString(orderDataMap));
        Response ordResponse = DrugService.callUnderlineFromInternal("yyt.drug.matched.list",
                JsonUtils.toJsonString(orderDataMap));
        logger.info("【外购处方单-根据条件查询药品匹配结果信息】, yyt.drug.matched.list response=" + JSONObject.toJSONString(ordResponse));
        logger.info("【外购处方单-根据条件查询药品匹配结果信息】, 匹配结果-->【ResultCode=" + ordResponse.getResultCode() + ",ResultMessage=" + ordResponse.getResultMessage());
        logger.info("【外购处方单-匹配药店药品信息-结束】, DrugMatchedRunnable,orderNo=" + orderNo);
    }
}
